<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/static/plugins/Buttons-1.4.0/css/buttons.bootstrap.min.css"/>
		<link rel="stylesheet" type="text/css" href="/static/plugins/bootstrapvalidator/dist/css/bootstrapValidator.min.css" />
		<style type="text/css">
			.insert {
				width: 100%;
				min-height: 300px;
				margin: 0 auto;
				text-align: center;
				padding-top: 10px;
				padding-bottom: 10px;
				border-radius: 10px;
				text-align: center;
				background-color: #ECF0F5;
			}
			.modal-content{
				border-radius: 20px;
			}
			.title {
				font-size: 24px;
				font-weight: bold;
				line-height: 40px;
				margin-bottom: 20px;
			}
			
			.main {
				width: 280px;
				margin: 0 auto;
				text-align: left;
			}
			
			.black {
				font-size: 25px;
				float: right;
			}
			
			.marginLeft {
				margin-left: 45px;
			}
			
			.error1,
			.error2,
			.error3,
			.error4,
			.error5,
			.error6 {
				display: none;
				color: red;
				font-size: 12px;
			}
			.inputTitle{
				display: inline-block;
				width: 100px;
				text-align: right;
			}
		</style>
	</head>

	<body>
		<div class="insert">
			<div class="title">
				新增用户
			</div>
			<div class="main">
				<p><span class="inputTille">用户权限：</span><input type="text" name="Roleid" id="Roleid" value="" placeholder="请输入1-3数字"/></p>
				<p class="error1"></p>
				<p><span class="inputTille">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span><input type="text" name="UserName" id="UserName" value="" /></p>
				<p class="error2"></p>
				<p><span class="inputTille">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</span><input type="password" name="Password" id="Password" value="" /></p>
				<p class="error3"></p>
				<p><span class="inputTille">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</span><input type="radio" name="Sex" id="" value="男" class="Sex" checked="checked" />男 <input type="radio" name="Sex" id="" value="女" class="Sex" />女</p>
				<p class="error4"></p>
				<p><span class="inputTille">邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：</span><input type="email" name="Email" id="Email" value="" /></p>
				<p class="error5"></p>
				<p><span class="inputTille">电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话：</span><input type="phone" name="Phone" id="Phone" value="" /></p>
				<p class="error6"></p>
				<p><button class="" type="button" data-dismiss="modal">取消</button><button class="marginLeft submit" data-dismiss="">提交</button>
					<button class=" marginLeft" type="button" data-dismiss="modal">返回</button>
				</p>
			</div>
		</div>
		<script src="/static/plugins/Buttons-1.4.0/js/buttons.bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/plugins/bootstrapvalidator/dist/js/bootstrapValidator.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				$(".submit").click(function() {
					var table = $('#table_id_example').DataTable();
					var isgo = true;
					var roleid=$("#Roleid").val();
					var username = $("#UserName").val();
					var pas=$("#Password").val();
					var xingBie = "";
					var sex = $(".Sex");
					var ret=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
					if(sex[0].checked == true) {
						xingBie = "男";
					} else {
						xingBie = "女";
					}
					var email = $("#Email").val();
					var phone = $("#Phone").val();
					if(roleid==""){
						isgo=false;
						$(".error1").css("display","block");
						$(".error1").html("用户权限不能为空！");
					}
					else{
						$(".error1").css("display","none");
					}
					if(username == "") {
						isgo = false;
						$(".error2").css("display", "block");
						$(".error2").html("姓名不能为空！");
					} else {
						$(".error2").css("display", "none");

					}
					if(pas == "") {
						isgo = false;
						$(".error3").css("display", "block");
						$(".error3").html("密码不能为空！");
					} else {
						$(".error3").css("display", "none");

					}
					if(phone == "") {
						isgo = false;
						$(".error6").css("display", "block");
						$(".error6").html("电话不能为空！");
					} else {
						$(".error6").css("display", "none");

					}
					if(email == "") {
						isgo = false;
						$(".error5").css("display", "block");
						$(".error5").html("邮箱不能为空！");
					}else {
						$.ajax({
							type: "post",
							url: "/getEmail",
							data: {
								email: email
							},
							success: function(data) {
								if(data['code']==0) {
									isgo = false;
									$(".error5").css("display", "block");
									$(".error5").html("邮箱已经被占用");
								} else {
									$(".error5").css("display", "none");
									if(isgo == true) {
										$.ajax({
											type: "post",
											url: "/user/add",
											data: {
												roleid:roleid,
												username: username,
												pas:pas,
												xingBie: xingBie,
												email: email,
												phone: phone,
											},
											success: function(data) {
												if(data['code']==0) {
													alert("信息添加成功！");
													table.draw(false);
												} else {
                                                    alert("信息添加失败！");
												}
											},
											error: function(data) {

											}
										});
									}
								}
							}
						})

					}
				});
			})
		</script>
	</body>

</html>